package com.huang.pool;

import java.util.concurrent.*;

/*
*  * new ThreadPoolExecutor.AbortPolicy() // 银行满了，还有人进来，不处理这个人的，抛出异常
 * new ThreadPoolExecutor.CallerRunsPolicy() // 哪来的去哪里！
 * new ThreadPoolExecutor.DiscardPolicy() //队列满了，丢掉任务，不会抛出异常！
 * new ThreadPoolExecutor.DiscardOldestPolicy() //队列满了，尝试去和最早的竞争，也不会抛出异常！
*
*
* */
public class Demo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
  //     ExecutorService threadpool = Executors.newSingleThreadExecutor();// 单个线程
    //     ExecutorService threadpool = Executors.newFixedThreadPool(6);// 固定线城池大小
     //  ExecutorService threadpool = Executors.newCachedThreadPool();// 可收缩  遇强则强
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 5, 3, TimeUnit.SECONDS
                , new LinkedBlockingQueue<>(3)
                , Executors.defaultThreadFactory()
                , new ThreadPoolExecutor.AbortPolicy());



        for (int i = 1; i <=8; i++) {
            FutureTask<Integer> command = new FutureTask<>(
                    () -> {
                        System.out.println(Thread.currentThread().getName() + "----->ok ");
                        return 111;
                    }
            );
            threadPoolExecutor.submit(
                    command
                   );
            System.out.println(command.get());

        }


    }
}
